<?php
/**
* 对象加载
* eg:
* obj::get('music')->getList();
**/
class obj {
	//对象数组
	public static $obj = array();
	
	//获取对象
	public static function get($className, $dir = '') {
	 
		$className = strtolower($className);
		
		//资源对象已创建 直接返回使用
		if(isset(self::$obj[$className]) && is_object(self::$obj[$className])) {
			return self::$obj[$className];
		}
		
		//加载文件资源类文件
		if(empty($dir))
			$file = dirname(__FILE__)."/{$className}.php";
		else
			$file = rtrim(trim($dir), '/')."/{$className}.php";
			
		$msg = '';
		if(file_exists($file)) {
			require $file;
			if(class_exists($className)) {
				return self::create($className);
			}else {
				$msg =  "no class {$className} in file {$file}"; //类名错误
			}
		}else {
			$msg = "no class file {$file}"; //类文件错误
		}
		self::debug($msg);
	}

	//创建资源对象
	function create($className) {
		if(isset(self::$obj[$className]) && is_object(self::$obj[$className])) {
			return self::$obj[$className];
		}else{
			self::$obj[$className] = new $className();
			return self::$obj[$className];
		}
	}
	
	function getList() {
		return self::$obj;
	}
	
	//错误提示
	function debug($msg) {
		exit($msg);
	}
	
}//end obj class
?>